<!DOCTYPE HTML>
<html>
<head>
    <title>My WebSocket</title>
</head>
 
<body>
Welcome<br/>
<input id="text" type="text" />
<div id="message">
</div>
</body>
<script src="https://cdn.bootcss.com/stomp.js/2.3.3/stomp.js"></script>
<script src="https://cdn.bootcss.com/sockjs-client/1.1.4/sockjs.js"></script>
<script type="text/javascript">
 
if (typeof WebSocket == 'undefined') {
    console.log('不支持websocket')
}
 
// 初始化 ws 对象
 
var ws = new WebSocket('ws://192.168.231.128:15674/ws');
 
// 获得Stomp client对象
var client = Stomp.over(ws);
 
// SockJS does not support heart-beat: disable heart-beats
//client.heartbeat.outgoing = 0;
//client.heartbeat.incoming = 0;
//client.debug = pipe('#second');
 
// 定义连接成功回调函数
var on_connect = function(x) {
    //data.body是接收到的数据
    client.subscribe("/queue/rabbitMQ.test", function(data) {
        var msg = data.body;
        alert("收到数据：" + msg);
    });
};
 
// 定义错误时回调函数
var on_error =  function() {
    console.log('error');
};
 
// 连接RabbitMQ
client.connect('admin', 'admin', on_connect, on_error, '/');
console.log(">>>连接上http://192.168.231.128:15674");
</script>
</html>